package com.maimao.order.client;

import com.maimao.core.constant.ServiceContainer;
import com.maimao.core.interceptor.FeignInterceptor;
import com.maimao.core.model.resp.Result;
import com.maimao.order.client.factory.GoodsFallBackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2021/1/15 2:16 下午
 */
@RequestMapping("/goods/goods")
@FeignClient(value = ServiceContainer.GOODS_SERVICE, fallbackFactory = GoodsFallBackFactory.class, configuration = FeignInterceptor.class)
public interface GoodsClient {

    /**
     * 下单修改库存
     *
     * @param oper     1:下单减库存 0：取消订单加库存
     * @param stockMap key:skuId value:购买数量
     */
    @PostMapping("/client/updateStock")
    public Result<Void> updateStock(@RequestParam("oper") Integer oper, @RequestBody Map<Long, Integer> stockMap);

    /**
     * 增加销量
     *
     * @param sellCountMap sellCountMap key:商品id value:要增加的销量
     */
    @PostMapping("/add-sellCount")
    Result<Void> addSellCount(@RequestBody Map<Long, Integer> sellCountMap);

    /**
     * 批量检查sku是否有效（商品是否下架 库存是否大于0且满足下单量） 下单时调用
     *
     * @param data key:skuId value:下单量
     * @return
     */
    @PostMapping("/check-sku-batch")
    Result<Boolean> checkSkuBatch(@RequestBody Map<Long, Integer> data);

    /**
     * 检查spu是否有效（商品是否下架） 下单时调用
     *
     * @param goodsIdList
     * @return
     */
    @PostMapping("/check-spu-batch")
    Result<Boolean> checkSpuBatch(@RequestBody List<Long> goodsIdList);

    @GetMapping("/client/queryBrandIdByGid")
    Result<Long> queryBrandIdByGoodsId(@RequestParam("goodsId") Long goodsId);
}
